home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / tstlrl.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  3KB  |  75 lines

  1. Program TstLRL;
  2.  
  3. { Example for the nwLock unit / NwTP 0.6 API. (c) 1993,1995, R.Spronk }
  4.  
  5. { Tests the following nwLock calls: (Logical Record Locking)
  6.  
  7.  LogLocalRecord
  8.  LockLogicalrecordSet
  9.  ReleaseLogicalRecord
  10.  ClearLogicalRecordSet
  11.  
  12. }
  13.  
  14. Uses nwLock; { using this unit will automatically set the locmode to 1 }
  15.  
  16. Var RecordName:string;
  17.     TimeOutTicks:word;
  18.  
  19. begin
  20. TimeOutTicks:=360; {wait 20 seconds before locking process times out}
  21.  
  22. writeln('TSTLRL: Test of logical record locking.');
  23. writeln('       -Start the exe on 2 or more workstations & enjoy the effect.');
  24. writeln;
  25. writeln('Suppose we want to perform a transaction on a file, where:');
  26. writeln('-we want to update (read&write) Records # 123, 678 and 056.');
  27. writeln;
  28. writeln('To do this, this program uses logical record locking in the following manner:');
  29. writeln('-It locks records #123,678 and 056 in Exclusive mode.');
  30. writeln(' (denying all attempts at locking by other stations.');
  31.  
  32. { Put the names of records-to-be-EXCLUSIVELY-locked in the 'logged record set' }
  33. RecordName:='#123';
  34. IF NOT LogLogicalRecord(RecordName,LD_LOG,0)
  35.  then writeln('LogRecord failed. Error# ',nwLock.result);
  36. { Note: The recordnames used have no linkage whatsover with physical
  37.         records. They form a logical representation of a physical record.
  38.         All processes involved in locking processes on the same data must
  39.         use the same naming convention }
  40. RecordName:='#678';
  41. IF NOT LogLogicalRecord(RecordName,LD_LOG,0)
  42.  then writeln('LogRecord failed. Error# ',nwLock.result);
  43. RecordName:='#056';
  44. IF NOT LogLogicalRecord(RecordName,LD_LOG,0)
  45.  then writeln('LogRecord failed. Error# ',nwLock.result);
  46.  
  47. { Lock all records that are currently stored in the 'logged record set' }
  48. writeln('Attempting to place locks on records.. ');
  49.  
  50.  
  51. IF NOT LockLogicalRecordSet(LD_LOCK,TimeoutTicks)
  52.  then writeln('LockLogicalRecordSet (after TimeOut=20 sec) failed. Error# ',nwLock.result);
  53.  
  54. if nwlock.result=0 { locking of records was successful }
  55.  then begin
  56.       { ---Update records, change records, etc.--- }
  57.  
  58.       { Readln to simulate update }
  59.       writeln('Now ''processing'' locked records. Press RETURN to release locks.');
  60.       readln;
  61.  
  62.       { Suppose we're done with record #123, but still need the other record
  63.         -unlock 1 record; keep record in log }
  64.       IF NOT ReleaseLogicalRecord('#123')
  65.        then writeln('ReleaseLogicalRecord Failed. Error# ',nwLock.result);
  66.  
  67.       writeln('Now ''processing'' still locked records');
  68.       end;
  69.  
  70. { unlock all records; clear 'logged record set' }
  71. IF NOT ClearLogicalRecordSet
  72.  then writeln('ClearLogicalRecordSet Failed. Error# ',nwLock.result);
  73.  
  74. end.
  75.